<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	<meta content="telephone=no" name="format-detection">
	<title>大米直播</title>
	<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
	<script src="js/jwplayer/jwplayer.js"></script>
	<script src="js/jwplayer/jwplayer.html5.js"></script>
	<!--<script src="js/jwplayer/jwpsrv_frq.js" type="text/javascript" charset="utf-8"></script>-->
	<!--<script src="js/jwplayer/jwpsrv.js" type="text/javascript" charset="utf-8"></script>-->
	<script type="text/javascript">jwplayer.key="lsUqQ+PB1edH+bYoMb85Yr5CuPlXyhK/ngcyNQ==";</script>
	<style type="text/css">
		.play-contral {
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
		}
		.play-contral .play-bg {
			width: 100%;
			height: 100%;
		}
		.play-contral .play-btn {
			position: absolute;
			top: 50%;
			left: 50%;
			width: 3rem;
			height: 3rem;
			margin-left: -1.5rem;
			margin-top: -1.5rem;
			cursor: pointer;
			z-index: 9;
		}
	</style>
</head>
<body style="margin:0px; padding:0px;">
	<div id="dami_player" class="dami-player"></div>
	<!-- 播放背景 -->
	<div class="play-contral" id="play-contral">
		<img src="images/bg.jpg" alt="" class="play-bg"/>
		<img src="images/play.png" alt="" class="play-btn" />
	</div>
	<script>
		/*
		 * 功能：获取不同的设备特有的字符串标识
		 */
        var sUserAgent = navigator.userAgent.toLowerCase();
        var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
        var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
        var bIsMidp = sUserAgent.match(/midp/i) == "midp";
        var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
        var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
        var bIsAndroid = sUserAgent.match(/android/i) == "android";
        var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
        var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";

		/*
		 * 功能：img全屏（将设备的高度赋给img）
		 */
		var deviceH = document.body.scrollHeight;
		$("#dami_player img").height(deviceH);
		
		/*
		 * 功能：获取地址栏信息：id等
		 */
		var IdJSON; //保存用户id，用户名
		var getIdInfo = function() {
			var urlVal = window.location.href;
			String.prototype.urlStr = function(name) {
				var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
				var r = this.substr(this.indexOf("\?")+1).match(reg);
				if (r!=null) return unescape(r[2]); return null;
			}
			IdJSON = {
				/*RoomName:urlVal.urlStr("RoomName"),
				RoomId:urlVal.urlStr("RoomId")*/
                "rid":2242
			}
		}
		getIdInfo();
		/*
		 * 功能： 传递用户id信息，请求视频数据
		 */
		var mobileDataUrl;	//移动视频地址
		var pcDataUrl;	//PC端地址
		var statusVal;	//判断是否有视频
		var imgVal;	//预览图
		
		$.ajax({
			type:"get",
			url:"http://192.168.1.12:3000/room_info",
			data: IdJSON,
			async:false,
			success: function(data) {
				console.log(data);
				mobileDataUrl = data.mobile;
				pcDataUrl = data.live;
				statusVal = data.status;
//				imgVal = userData.img;
			}
		});

		
		/*
		 * 功能：设置背景预览图
		 */
		
		$("#play-contral .play-bg").attr("src", imgVal);
		
		/*
		 * 功能：判断是在移动或pc设备上浏览
		 */
//		function play() {
			var player;
			if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
				//status为0，直播结束。 status为1，正在直播
				if(statusVal == 3) {
					alert("直播已结束");
				} else if (statusVal == 1) {
					player = jwplayer("dami_player").setup({
						width: document.body.scrollWidth,
						height: document.body.scrollHeight,
						/*image: "",*/
						autostart: true,
						androidhls: true,
						primary: 'mp4',
						controls: false,
						file: mobileDataUrl
						/*file:"media.mp4"*/
					});
				}
	        } else {
	        	//status为0，直播结束。 status为1，正在直播
	        	if(statusVal == 3) {
					alert("直播已结束");
				} else if (statusVal == 1) {
					$("#play-contral").css({
						"width": "380px",
						"height": "640px"
					})
					player = jwplayer("dami_player").setup({
						width: 380,
						height: 640,
						/*image: "",*/
						dock: false,
						autostart: true,
						primary: 'flash',
						controls: false,
						file: pcDataUrl
						/*file:"media.mp4"*/
					});
				}
	        }
//		}
		/*
		 * 功能：点击播放功能开始播放
		 */
		$("#play-contral").click(function() {
			$(this).hide();
			
			 if(player.getState() != 'PLAYING'){  
		        player.play(true);  
		        this.value = 'Pause';  
		    }else {  
		        player.play(false);  
		        this.value = 'Play';  
		    }
			
//			play();
		})
	</script>
</body>
</html>




